//路由主组件
import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

export const constantRoutes = [
  //登录页面
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  //404错误页面
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  //首页
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        name: 'Dashboard',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },
  //导入Excel页面
  {
    path: '/import',
    component: Layout,
    children: [
      {
        path: '',
        name: 'import',
        component: () => import('@/views/import'),
      }
    ],
   
  },

  // *符号代码上面的所有路径，如果上面没有一个匹配就跳转到404错误页面
  { path: '*', redirect: '/404', hidden: true }
]

//导入子路由
import departments from '@/router/modules/departments'    //组织架构
import employees from '@/router/modules/employees'        //员工
import permission from '@/router/modules/permission'      //权限管理
import social from '@/router/modules/social'              //社保
import attendances from '@/router/modules/attendances'    //考勤
import salarys from '@/router/modules/salarys'            //工资
import approvals from '@/router/modules/approvals'        //审批
import setting from '@/router/modules/setting'            //公司设置

//导出子路由
export const asyncRoutes = [
  departments,//组织架构
  employees,//员工
  permission,//权限管理
  social,//社保
  attendances,//考勤
  salarys,//工资
  approvals,//审批
  setting//公司设置
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: [...constantRoutes, ...asyncRoutes]
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter () {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
